home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 4
/
Mac Giga-ROM 4.0 - 1993.toast
/
FILES
/
DEV
/
I-Z
/
Simple_Tools.cpt
/
SimpleTools.c
< prev
next >
Wrap
Text File
|
1985-07-19
|
9KB
|
272 lines
/*
Title : SimpleDemo.c
Author : Erik Kilk
Date : June 9, 1985
Synopsis: A demonstration of the use of SimpleTools with
other toolbox calls.
The SimpleTools routines are being freely distributed.
You may use them, distribute your applications which use them,
and copy them if you send $10 to $25 to:
Erik Kilk
325 San Leandro Way
San Francisco, CA 94127
Link this demonstration program with SimpleTools.o.
*/
/*******************************/
/* INCLUDE FILES FOR TOOLBOX */
/*******************************/
#include <qd.h>
#include <mem.h>
#include <font.h>
#include <qdvars.h>
#include <misc.h>
#include <win.h>
#include <string.h>
#include <stdio.h>
/***********************************************/
/* DEFINITIONS FOR THE SIMPLETOOLS MENU CALL */
/***********************************************/
#define itemdisable 0L
#define itemenable 1L
#define itemcheck 2L
#define itemuncheck 3L
/**************************************/
/* GLOBAL VARIABLES AND FUNCTIONS */
/**************************************/
int circspeed = 50; /* rate of drawing new circles */
extern windowptr windowpoint(); /* defined in SimpleTools */
extern char applestring[]; /* defined in SimpleTools */
extern int windmenu; /* defined in SimpleTools */
/*********************/
/* Odds and Ends */
/*********************/
leave() /* Attached to the Quit menu */
{
exit(0);
}
nop() /* Attached as a null pointer */
{
}
/******************************/
/* Clear the front window */
/******************************/
ourclear()
{
rect therect; /* rectangle to clear */
if ((long)frontwindow() != 0L) { /* if there is a front window */
setport (frontwindow()); /* set it for output */
setrect ( &therect, 0, 0, 512, 400);/* make a rectangle */
fillrect ( &therect, qdvars.white); /* erase the rectangle in window */
}
}
/***********************/
/* Sketch Window */
/***********************/
sketactivate() /* Attached to sketch's activate */
{ /* Disable the whole sketch menu */
menu ("Sketch", "", itemenable);
menu ("Edit", "", itemenable);
menu ("Edit", "Clear", itemenable);
}
sketdeactivate() /* Attached to sketch's deactivate */
{ /* Enable the whole sketch menu */
menu ("Sketch", "", itemdisable);
menu ("Edit", "Clear", itemdisable);
menu ("Edit", "", itemdisable);
}
sketch(x,y) /* follow mouse while it's down */
int x,y; /* we will get passed the mouse point */
{
point xy, lastxy; /* points of interest */
moveto (x, y); /* position pen at mouse down point */
while ( stilldown() ) { /* while the button is pressed */
getmouse (&xy); /* read the mouse position */
if ( (xy.a.v != lastxy.a.v) || (xy.a.h != lastxy.a.h) ) {
lineto (xy.a.h, xy.a.v); /* if mouse moved, draw a line to it */
lastxy.a.v = xy.a.v; /* record position so we can detect */
lastxy.a.h = xy.a.h; /* a move. */
}
}
}
setpensize(size) /* Attached to pen size menus */
char *size; /* menu item name given to us */
{
static char lastsize[5]={'1','\0'}; /* keep last setting */
int isize; /* size to set the pen to */
menu ("Sketch", lastsize, itemuncheck); /* remove old check mark */
menu ("Sketch", size, itemcheck); /* install a new check mark */
strcpy (lastsize, size); /* save size for the next setpensize */
isize = atoi (size); /* convert to a number */
withwindow ("Sketch"); /* set output to the sketch window */
pensize (isize, isize); /* set the pen size */
}
/**************************/
/* The Circles Window */
/**************************/
int newabs(x) /* an absolute value funtion */
int x;
{
if (x < 0)
x = -x;
return (x);
}
circles() /* draw a random sized circle */
{
static windowptr wind = (windowptr) 0; /* keep "circle" windowptr */
static int speed = 1; /* current count between new circles */
register int cx, cy; /* center of the circle */
int r, b, rd; /* right and bottom edges */
register pattern *color; /* color for the circle */
rect therect; /* rectangle to draw circle in */
if ( --speed == 0) { /* count, and if it reaches zero... */
speed = circspeed; /* reset the count */
if ((long)wind == 0L) /* get window pointer if we need */
wind = windowpoint ("Circles"); /* save window for next time */
setport (wind); /* set output to the circle window */
r = wind->portrect.a.right; /* get current size of window */
b = wind->portrect.a.bottom;
cx = newabs(random()) % (r-30) + 1; /* pick a random location */
cy = newabs(random()) % (b-30) + 1;
rd = newabs(random()) % 25 + 5; /* and size */
setrect ( &therect, cx, cy, cx+rd, cy+rd); /* make a rectangle */
switch ( newabs(random()) % 4) { /* pick a color */
case 0: color = &qdvars.dkgray; break;
case 1: color = &qdvars.ltgray; break;
case 2: color = &qdvars.gray; break;
case 3: color = &qdvars.black; break;
}
filloval ( &therect, *color); /* make the circle */
}
}
setspeed(name) /* attached to circle's menu */
char *name;
{
menu ("Circles","Slow", itemuncheck); /* another way to uncheck last */
menu ("Circles","Medium", itemuncheck); /* just uncheck everything */
menu ("Circles","Fast", itemuncheck);
menu ("Circles", name, itemcheck); /* then check the current */
if (strcmp("Slow", name) ==0) circspeed = 100; /* set the reset count */
else if (strcmp("Medium", name) ==0) circspeed = 50;
else if (strcmp("Fast", name) ==0) circspeed = 1;
}
/****************************************/
/* Generate a new window by command */
/****************************************/
nwindow() /* command to attatch to new window menu */
{
static topplace = 100; /* remember where to put next window */
char newname[255]; /* string storage for window's name */
strcpy (newname, "New Window"); /* default window name */
retry: /* prompt for the name from user */
if (prompt ("Give me a unique name for the new window:", newname)) {
if ( (long)windowpoint(newname) != 0L ) {
if (message ("Sorry, a window by that name already exists."))
goto retry; /* if exists, ask for another name */
} else {
if ( strlen(newname) > 0) { /* if ok, make the new window */
/* then it is new */
window (newname, 20,topplace, 400,topplace+30, nop, nop, nop, nop);
topplace += 5; /* adjust top for next new window */
if (topplace > 300) topplace = 100; /* reset top if too low */
}
}
}
}
/**********************/
/* About SimpleDemo */
/**********************/
tellabout() /* for the About SimpleDemo menu choice */
{
char mess[255]; /* string to form a message */
strcpy (mess,"SimpleDemo -- Copyright 1985 Erik Kilk\r");
strcat (mess,"A demonstration of the use of SimpleTools");
strcat (mess," as a Macintosh toolbox aid.");
message (mess); /* display the string in a dialog */
}
usageinfo() /* messages for Usage Info menu choice */
{
char mess[255]; /* string to form a message */
strcpy (mess,"You may use, distribute your programs which use, ");
strcat (mess,"and copy SimpleTools if you send ");
strcat (mess,"$10 - $25 to ...");
if (message (mess)) { /* if OK pressed for first message */
strcpy (mess, "Erik Kilk\r325 San Leandro Way\r");
strcat (mess, "San Francisco, CA 94127");
if (message (mess)) /* if OK pressed for 2nd message */
message ("Thank you for your support."); /* show final message */
}
}
/**********************/
/* Initialization */
/**********************/
setup() /* to be called with Start Demo menu choice */
{
window ("Sketch", 265, 60, 490, 320,sketactivate,sketdeactivate,
nop, sketch); /* display the sketch pad window */
window("Circles", 20, 60, 245, 320,nop, nop, nop, nop); /* circles */
menu ("Edit", "Clear", ourclear); /* install our edit menu */
menu ("Sketch", "Pen Size", itemdisable); /* install sketches menu */
menu ("Sketch", "1", setpensize);
menu ("Sketch", "2", setpensize);
menu ("Sketch", "3", setpensize);
menu ("Sketch", "4", setpensize);
menu ("Sketch", "5", setpensize);
menu ("Sketch", "6", setpensize);
menu ("Circles", "Speed", itemdisable); /* install circles menu */
menu ("Circles", "Slow", setspeed);
menu ("Circles", "Medium", setspeed);
menu ("Circles", "Fast", setspeed);
menu ("Circles", "Medium", itemcheck);
menu ("Commands", "New Window", nwindow); /* install Commands menu */
menu ("Commands", "New Window", itemenable);
menu ("Commands", "Start Demo", itemdisable);
run (circles); /* keep drawing circles */
}
main()
{
simpletools("About SimpleDemo"); /* setup Apple and Edit menus */
menu ("File", "Quit", leave); /* setup a way out of this program */
menu ("Commands", "Start Demo", setup); /* and a start */
menu ("Commands", "New Window", itemdisable );
menu ("Commands", "Usage Info", usageinfo);
menu ( applestring, "About SimpleDemo", tellabout);
menu ( applestring, "About SimpleDemo", itemenable);
for (;;) simpleevents(); /* process events */
}